<script lang="ts" setup>
import { reactive,onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// do not use same name with ref
const formData = reactive({
    form: {
        id:1,
        zcjl: '50',
        dljlkg: '开启',
        pc1: '',
        pc2: '',
        gz1: '',
        gz2: '',
        hywx: '',
        hywx1: '',
        yzm: '开启',
        yzmxz: '开启',
        xzcs: '10',
    }

})

const onSubmit = () => {
    console.log('submit!')
}

import axios from 'axios'

const getDlpz = () => {
    //参考接口文档，请求用户数据
    axios.get("/api/dlpz/").then((response) => {
        console.log(response, "网站信息数据")
        //更新用户数据
        formData.form = response.data[0]
        console.log(formData.form, "接收网站信息数据")
    })  
}

onMounted(() => {
    getDlpz()
})

const updateDlpz = () => {
    console.log(formData.form, "<-----1111修改网站信息数据")
    axios.patch("/api/dlpz/1/",
        formData.form,
        { headers: { "Content-Type": "application/json" } }   //application/json
    ).then((response) => {
        console.log(response, "<-----修改网站信息数据")
        // 更新用户数据
        formData.form = response.data
        //console.log(response.data[0], "<------接收网站信息数据")
        // 重新获取数据
        //getWzxx()
        ElMessage({
            type: "success",
            message: "信息保存成功"
        })
    })

}


</script>


<template>
    <el-form :model="formData.form" label-width="auto" style="max-width: 800px">
        <el-form-item label="注册奖励">
            <el-input v-model="formData.form.zcjl" />
            <h3>新用户注册奖励（整数）</h3>
        </el-form-item>
        <el-form-item label="登陆奖励开关">
            <el-select v-model="formData.form.dljlkg" placeholder="please select your zone">
                <el-option label="开启" value="shanghai" />
                <el-option label="关闭" value="beijing" />
            </el-select>
        </el-form-item>
        <el-form-item label="PC微信登录appid">
            <el-input v-model="formData.form.pc1" />
            <h3>PC微信登录appid(微信开放平台网页应用APPID)</h3>
        </el-form-item>
        <el-form-item label="PC微信登录appsecret">
            <el-input v-model="formData.form.pc2" />
            <h3>PC微信登录appsecret(微信开放平台网页应用AppSecret)</h3>
        </el-form-item>
        <el-form-item label="微信公众平台Appid">
            <el-input v-model="formData.form.gz1" />
        </el-form-item>
        <el-form-item label="微信公众平台Appsecret">
            <el-input v-model="formData.form.gz2" />
        </el-form-item>
        <el-form-item label="互亿无线APIID">
            <el-input v-model="formData.form.hywx" />
            <h3>短信验证码http://www.ihuyi.com/互亿无线后台->验证码、短信通知->账号及签名->APIID</h3>
        </el-form-item>
        <el-form-item label="互亿无线key">
            <el-input v-model="formData.form.hywx1" />
            <h3>短信验证码互亿无线后台->验证码、短信通知->账号及签名->APIKEY</h3>
        </el-form-item>
        <el-form-item label="短信验证码开关">
            <el-select v-model="formData.form.yzm" placeholder="please select your zone">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
            <h3>短信验证码开关，关闭后不再发送真实验证码，采用默认验证码123456</h3>
        </el-form-item>
        <el-form-item label="短信验证码IP限制开关">
            <el-select v-model="formData.form.yzmxz" placeholder="please select your zone">
                <el-option label="开启" value="开启" />
                <el-option label="关闭" value="关闭" />
            </el-select>
        </el-form-item>
        <el-form-item label="短信验证码IP限制次数">
            <el-input v-model="formData.form.xzcs" />
            <h3>同一IP限制短信发送次数</h3>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="updateDlpz">保存</el-button>
        </el-form-item>
    </el-form>
</template>

<style scoped>
.el-form-item h3 {
    color: #999;
    font-size: 14px;
}

.el-button {
    margin-left: 188px;
}
</style>